Conditions | 5 |
Paths | 8 |
Total Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
56 | $.ajax = function (settings) { |
||
57 | // create settings for compatibility with ajaxSetup |
||
58 | settings = jQuery.extend(settings, jQuery.extend({}, jQuery.ajaxSettings, settings)); |
||
59 | |||
60 | var port = settings.port; |
||
61 | |||
62 | switch (settings.mode) { |
||
|
|||
63 | case "abort": |
||
64 | if (pendingRequests[port]) { |
||
65 | pendingRequests[port].abort(); |
||
66 | } |
||
67 | return pendingRequests[port] = ajax.apply(this, arguments); |
||
68 | case "queue": |
||
69 | var _old = settings.complete; |
||
70 | settings.complete = function () { |
||
71 | if (_old) |
||
72 | _old.apply(this, arguments); |
||
73 | jQuery([ajax]).dequeue("ajax" + port); |
||
74 | ; |
||
75 | }; |
||
76 | |||
77 | jQuery([ajax]).queue("ajax" + port, function () { |
||
78 | ajax(settings); |
||
79 | }); |
||
80 | return; |
||
81 | case "sync": |
||
82 | var pos = synced.length; |
||
83 | |||
84 | synced[pos] = { |
||
85 | error: settings.error, |
||
86 | success: settings.success, |
||
87 | complete: settings.complete, |
||
88 | done: false |
||
89 | }; |
||
90 | |||
91 | syncedData[pos] = { |
||
92 | error: [], |
||
93 | success: [], |
||
94 | complete: [] |
||
95 | }; |
||
96 | |||
97 | settings.error = function () { |
||
98 | syncedData[pos].error = arguments; |
||
99 | }; |
||
100 | settings.success = function () { |
||
101 | syncedData[pos].success = arguments; |
||
102 | }; |
||
103 | settings.complete = function () { |
||
104 | syncedData[pos].complete = arguments; |
||
105 | synced[pos].done = true; |
||
106 | |||
107 | if (pos == 0 || !synced[pos - 1]) |
||
108 | for (var i = pos; i < synced.length && synced[i].done; i++) { |
||
109 | if (synced[i].error) synced[i].error.apply(jQuery, syncedData[i].error); |
||
110 | if (synced[i].success) synced[i].success.apply(jQuery, syncedData[i].success); |
||
111 | if (synced[i].complete) synced[i].complete.apply(jQuery, syncedData[i].complete); |
||
112 | |||
113 | synced[i] = null; |
||
114 | syncedData[i] = null; |
||
115 | } |
||
116 | }; |
||
117 | } |
||
118 | return ajax.apply(this, arguments); |
||
119 | }; |
||
120 | |||
122 |